const jwt = require("jsonwebtoken")
let md5 = require("md5")



let api_url = "http://localhost:3000"


// 密码加密
function md(password) {
    return md5(md5(password + "呵呵，猜不到吧") + "$%^(@##@()")
}


// 生成token
function signtoken(mid) {
    return jwt.sign({ mid }, "哈哈0411", { expiresIn: 60*60 })
}

// 解析token
function verifytoken(authorization) {
    try {
        return jwt.verify(authorization, "哈哈0411")

    } catch (error) {

        return null

    }
}





module.exports = {
    api_url,
    md,
    signtoken,
    verifytoken
}